// components/li_list.js
const app = getApp()
const util = require('../../utils/util.js')
var animation = wx.createAnimation({
        duration: 800,
        timingFunction: "ease",
})
Component({
  /**
   * 组件的属性列表
   */
  properties: {
          isCollection: {
                  type: Boolean,
                  value: false
          },
          spid: {
                  type: String,
                  value: 'spid'
          },
          hits: {
                  type: String,
                  value: '影响力'
          },
          nums:{
                  type:Object,
                  value:'打赏金额'
          }
  },

  /**
   * 组件的初始数据
   */

  data: {
          show:false,
          actmun:'0',
          shange:'',
          inUrl: "images/collect_h.png",
          onUrl: "images/collect.png",
          toastshow: false,
          contens: "",
          jinbi:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
          //   收藏
          iscollect: function (e) {
                  var that = this
                  let isc = e.currentTarget.dataset.isc
                  that.setData({ 
                          isCollection: !isc
                   });
                  var data = {
                          userId: wx.getStorageSync('userInfo').id,
                          videoId: e.currentTarget.dataset.id
                  } 
                  var header = {
                          'authorization': wx.getStorageSync('tekon'),
                          'content-type': "application/x-www-form-urlencoded"
                  }       
                  if (isc==false){
                          //收藏
                          util.formhttp(app.globalData.appurl +'/qinqiang/like', 'POST', data, header, (data)=>{
                                //   console.log(data)
                                  var that=this
                                  if (data.data.missionAccomplished == 1) {
                                        that.setData({
                                                toastshow: true,
                                                contens: "奖励第一次收藏的你",
                                                jinbi: data.data.missionReward
                                        })
                                          setTimeout(function(){
                                                  that.setData({
                                                          toastshow: false
                                                          })
                                          },3000)
                                  }
                          });   
                 }else{
                         //取消收藏   
                          util.formhttp(app.globalData.appurl + '/qinqiang/removeLike', 'POST', data, header,null);
                 }          
                  wx.showToast({
                          title: !isc ? '收藏成功' : '取消成功',
                          icon: 'none',
                          duration: 2000
                  }) 
          },
          dashuang:function(e){
                  console.log(e.currentTarget.dataset.jine )
                  if (e.currentTarget.dataset.jine <= e.currentTarget.dataset.total) {
                          this.setData({
                                  actmun: 2,
                                  shange:e.currentTarget.dataset.jine
                          }) 
                  }else{
                          this.setData({
                                  actmun: 0,
                          })
                  }
                  this.setData({
                          show: true,
                  })
          },
          actmun:function(e){
                  this.setData({
                          actmun: e.currentTarget.dataset.num
                  });
                  if (e.currentTarget.dataset.jine <=e.currentTarget.dataset.total){
                          this.setData({
                                  shange: e.currentTarget.dataset.jine
                          }) 
                  }else{
                          wx.showToast({
                                  title: '金币不足',
                                  image: 'images/nas.png',
                                  duration: 2000,
                                  mask: true,
                          })
                  }
          },
    dsOperation:function(e){
     //完成打赏请求
            if (this.data.shange == "") {
                    wx.showToast({
                            title: '请选打赏现金额',
                            icon: "none",
                            duration: 3000,
                            mask: true,
                    })
            } else {
                   
                    console.log(this.data.shange)
                    var data = {
                            videoId: e.currentTarget.dataset.id,
                            coins: this.data.shange
                    }
                    var header = {
                            'authorization': wx.getStorageSync('tekon'),
                            'content-type': "application/x-www-form-urlencoded"
                    }
                    util.formhttp(app.globalData.appurl +'/reward', 'POST', data, header, this.suuc);
                    this.setData({
                            show: false,
                            actmun: '20',
                            shange: ''
                    })
            }
    },
          suuc:function(res){
                  console.log(res.message)
                  if (res.message == "success"){
                          wx.showToast({
                                  title: '打赏成功',
                                  icon: "none",
                                  duration: 3000,
                                  mask: true,
                          })
                  }
          },
          quxiao:function(){
                  this.setData({
                          show: false,
                  })
          }

  }
})
